// (c) Copyright 2013-2014 Stephen Gold <sgold@sonic.net>
// Distributed under the terms of the GNU General Public License

/*
 This file is part of the Bats Game.

 The Bats Game is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by the
 Free Software Foundation, either version 3 of the License, or (at your
 option) any later version.

 The Bats Game is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.

 You should have received a copy of the GNU General Public License
 along with the Bats Game.  If not, see <http://www.gnu.org/licenses/>.
 */
package bats.unit;

import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import java.util.logging.Logger;

/**
 * A potential target for attack.
 *
 * @author Stephen Gold <sgold@sonic.net>
 */
public class Target {
    // *************************************************************************
    // constants

    /**
     * special score for excluded targets
     */
    final public static float excludedScore = Float.NEGATIVE_INFINITY;
    /**
     * message logger for this class
     */
    final private static Logger logger =
            Logger.getLogger(Target.class.getName());
    // *************************************************************************
    // fields
    /**
     * The higher the score, the higher the priority of this target.
     */
    private float score = excludedScore;
    /**
     * unit associated with this target
     */
    final private Spatial unit;
    /**
     * world location of this target
     */
    final private Vector3f worldLocation;
    // *************************************************************************
    // constructor

    /**
     * Instantiate a target with the specified location and unit.
     *
     * @param worldLocation (not null)
     * @param unit (not null)
     */
    public Target(Vector3f worldLocation, Spatial unit) {
        assert worldLocation != null;
        assert unit != null;

        this.worldLocation = worldLocation.clone();
        this.unit = unit;
    }
    // *************************************************************************
    // new methods exposed

    /**
     * Exclude this target from selection.
     */
    public void exclude() {
        score = excludedScore;
    }

    /**
     * Get the numeric score for this target.
     */
    public float getScore() {
        return score;
    }

    /**
     * Access the unit associated with this target.
     *
     * @return reference to pre-existing unit, or null
     */
    public Spatial getUnit() {
        return unit;
    }

    /**
     * Copy the world location of this target.
     *
     * @return a new vector
     */
    public Vector3f getWorldLocation() {
        return worldLocation.clone();
    }

    /**
     * Alter the score for this target.
     *
     * @param newScore
     */
    public void setScore(float newScore) {
        score = newScore;
    }
}